<template>
<section>
    <section class="mk-add-pop">
        <el-form ref="formAdd" :model="form" :rules="rules" label-width="100px">
            <mk-get-row>
                <el-form-item label="资历类型" prop="type">
                    <el-select v-model="form.type" placeholder="请选择" @change="typeChange">
                        <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </mk-get-row>
            <mk-get-row>
                <el-form-item label="开始时间" prop="start_time">
                    <el-date-picker v-model="form.start_time" type="month" placeholder="选择开始时间">
                    </el-date-picker>
                </el-form-item>
            </mk-get-row>
            <mk-get-row>
                <el-form-item label="结束时间" prop="end_time">
                    <el-date-picker v-model="form.end_time" type="month" placeholder="选择结束时间">
                    </el-date-picker>
                </el-form-item>
            </mk-get-row>
            <mk-get-row>
                <el-form-item label="单位/公司" prop="unit">
                    <el-input v-model="form.unit" size="mini" class="input-one" clearable placeholder="请输入单位/公司名称"></el-input>
                </el-form-item>
            </mk-get-row>
            <mk-get-row v-if="form.type == 1">
                <el-form-item label="职位">
                    <el-input v-model="form.position" size="mini" class="input-one" clearable placeholder="请输入职位名称"></el-input>
                </el-form-item>
            </mk-get-row>
            <mk-get-row v-if="form.type == 0">
                <el-form-item label="专业">
                    <el-input v-model="form.position" size="mini" class="input-one" clearable placeholder="请输入专业名称"></el-input>
                </el-form-item>
            </mk-get-row>
            <mk-get-row>
                <el-form-item label="是否有效">

                    <el-radio-group v-model="form.show" size="mini">
                        <el-radio :label="1" border>是</el-radio>
                        <el-radio :label="0" border>否</el-radio>
                    </el-radio-group>
                </el-form-item>
            </mk-get-row>
            <el-divider />
            <mk-get-button @save="save" @close="close(true)" />
        </el-form>
    </section>
</section>
</template>

<script>
import MkGetRow from "@/components/common/mk-get-row";
import MkGetButton from "@/components/common/mk-get-button";
import MkBackList from "@/components/common/mk-back-list";
import {
    experienceCreate,
    experienceUpdate
} from "@/api/modules/sys.personal.experience.api";

export default {
    name: "get-experience-info",
    components: {
        MkBackList,
        MkGetButton,
        MkGetRow
    },
    props: {
        updateData: {
            type: Object,
            default () {
                return {};
            }
        },
    },
    created() {

        if (this.updateData && this.updateData.id) {
            this.form = this.updateData
            this.isAdd = false
        }
    },
    data() {
        return {
            commonKey: 0,
            typeOptions: [{
                value: 1,
                label: '工作'
            }, {
                value: 0,
                label: '教育'
            }],
            form: {
                type: 1,
                show: 1
            },
            isAdd: true,
            rules: {
                type: [{
                    required: true,
                    message: '请选择资历类型',
                    trigger: 'blur'
                }, ],
                start_time: [{
                    required: true,
                    message: '请选择开始时间',
                    trigger: 'blur'
                }, ],
                unit: [{
                    required: true,
                    message: '请输入单位/公司名称',
                    trigger: 'blur'
                }, ],

            }
        }
    },
    methods: {
        typeChange() {
            this.form.position = ""
        },
        save() {
            this.$refs['formAdd'].validate((valid) => {
                if (valid) {
                    let _FUC = ''
                    _FUC = this.isAdd ? experienceCreate : experienceUpdate
                    let msg = this.isAdd ? '添加成功！' : '修改成功！'
                    _FUC(this.form).then(res => {
                        this.$toast.success(msg)
                        this.$emit('close', true);
                    }).catch(err => {
                        console.log(err)
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        close(show) {
            if (show) {
                this.$toast.confirmSave().then(() => {
                    this.$emit('close');
                });
            } else {
                this.$emit('close');
            }
        }
    }
}
</script>

<style lang="scss" scoped>

</style>
